package com.example.comzg24_2.updata

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.example.base.url.mvvm.BaseActivity
import com.example.comzg24_2.R
import com.example.comzg24_2.databinding.ActivityResetBinding
import com.example.comzg24_2.login.LoginViewModel
@Route(path = "/app/resetActivity")
class ResetActivity : BaseActivity<ActivityResetBinding,LoginViewModel>(){
    var con = "0"
    override fun initView() {
        val name = SPUtils.getInstance().getString("name")
        viewModel.CodeLogin(name)

        binding.btnReset.setOnClickListener {
            viewModel.UpDataLogin(name,con,binding.etPsw.text.toString())
        }
    }

    override fun initData() {
        viewModel.codeSuccess.observe(this){
            if(it.code==200){
                con = it.data.content.substring(8,14)
            }
        }

        viewModel.upDataSuccess.observe(this){
            if(it.code==200){
                ToastUtils.showLong(it.message)
                ARouter.getInstance().build("/app/loginActivity").navigation()
            }
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_reset
    }

    override fun getViewModel(): Class<LoginViewModel> {
        return LoginViewModel::class.java
    }

}